﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;

using ERPStore.Extensions;
using ERPStore.Web.Routing;
using ERPStore.Web.Html;

namespace ERPStore.Coupons.Controllers
{
	public class IncentiveController : ERPStore.Web.Controllers.StoreController
	{
		public IncentiveController(ERPStore.Services.ICartService cartService
			, ERPStore.Services.IIncentiveService incentiveService)
		{
			this.CartService = cartService;
			this.IncentiveService = incentiveService;
		}

		protected ERPStore.Services.ICartService CartService { get; private set; }
		protected ERPStore.Services.IIncentiveService IncentiveService { get; private set; }

		[ERPStore.Web.Controllers.ActionFilters.TrackerActionFilter]
		public ActionResult RemoveCoupon(string id)
		{
			var cart = CartService.GetCurrentCart(User);
			if (cart == null)
			{
				if (Request.UrlReferrer != null)
				{
					return Redirect(Request.UrlReferrer.PathAndQuery);
				}
				return RedirectToERPStoreRoute(ERPStore.Web.Routing.ERPStoreRoutes.HOME);
			}

			IncentiveService.RemoveCoupon(cart, id, User);

			var url = CartService.GetCurrentCartHref(cart);
			return Redirect(url);
		}

	}
}
